package org.geektimes.projects.user.service.impl;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.orm.jpa.DelegatingEntityManager;
import org.geektimes.projects.user.repository.DatabaseUserRepository;
import org.geektimes.projects.user.repository.UserRepository;
import org.geektimes.projects.user.service.UserService;
import org.geektimes.projects.user.sql.DBConnectionManager;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 雪蓑
 * @Date: 2021/3/2 上午11:52
 * @Discription //todo
 */
public class UserServiceImpl implements UserService {


    @Resource(name = "bean/EntityManager")
    private EntityManager entityManager;

    @Override
    public boolean register(User user) {
        entityManager.persist(user);
        return Boolean.TRUE;
    }

    @Override
    public boolean deregister(User user) {
        return false;
    }

    @Override
    public boolean update(User user) {
        return false;
    }

    @Override
    public User queryUserById(Long id) {
        return null;
    }

    @Override
    public User queryUserByNameAndPassword(String name, String password) {
        return null;
    }

    @Override
    public User queryUserByName(String name) {
        String sql = "select * from user where name = " + name;
        Query query = entityManager.createQuery(sql);
        List userList = query.getResultList();
        return (User) userList.get(0);
    }
}
